package com.joysuch.wwyt.api.sync.service.impl;

import com.joysuch.wwyt.api.sync.SyncConstants;
import com.joysuch.wwyt.api.sync.service.BaseSyncCardRecordService;
import com.joysuch.wwyt.api.sync.service.BaseSyncCreditCardRecordService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class BaseSyncCardRecordServiceImpl implements BaseSyncCardRecordService {

    @Autowired
    private BaseSyncCreditCardRecordService baseSyncCreditCardRecordService;


   // @Scheduled(cron = "0 0/5 * * * ?")
    @Override
    public ResultBean syncCreditCardRecord() {
        log.debug("车辆出入信息列表同步Job 开始 ...");
        Set<String> bukrs = SyncConstants.unitCodeMap.keySet();
        List<String> msgList = new ArrayList<>();
        Integer typeFlag = 1;
        for (String companyCode : bukrs) {
            try {
                ResultBean result = syncCreditCardRecordByCompany(companyCode, typeFlag);
                msgList.add(result.getData().toString());
            } catch (Exception e) {
                log.error("车辆出入信息列表同步出错： companyCode={}", companyCode, e);
            }
        }
        log.info("车辆出入信息列表同步Job 结束 ...");
        return ResultBean.success(msgList);
    }

    @Override
    public ResultBean syncCreditCardRecordByCompany(String companyCode, Integer typeFlag) {
       return baseSyncCreditCardRecordService.syncCreditCardRecordByCompany(companyCode,typeFlag);
    }


}
